package com.oa.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.oa.bean.Pager;
import com.oa.bean.TDept;

public class TDept_hqq_DaoImp  implements TDept_hqq_Dao{
	private SessionFactory sessionFactory;
	private Session session;
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	@Override
	public TDept save(TDept t) {
		session = sessionFactory.getCurrentSession();
		session.beginTransaction();
		session.save(t);
		session.getTransaction().commit();
		return t;
	}

	@Override
	public void delete(TDept t) {
		session = sessionFactory.getCurrentSession();
		session.beginTransaction();
		session.delete(t);
		session.getTransaction().commit();
		
	}

	@Override
	public TDept uqdate(TDept t) {
		session = sessionFactory.getCurrentSession();
		session.beginTransaction();
		session.saveOrUpdate(t);
		session.getTransaction().commit();
		return t;
	}

	@Override
	public TDept select(Integer pk) {
		session = sessionFactory.openSession();
		Query query = session.createQuery("from TObject t where t.objectnum = ?");
		query.setParameter(0, pk);
		Object obj=query.uniqueResult();
		if(obj!=null){
			return (TDept)obj;
		}
		return null;
	}

	@Override
	public List<TDept> selects() {
		session = sessionFactory.openSession();
		Query query = session.createQuery("from TObject");
		@SuppressWarnings("unchecked")
		List<TDept> list = query.list();
		return list;
	}

	@Override
	public int queryId(TDept t) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void close() {
		// TODO Auto-generated method stub
		
	}

}
